package com.action.school;

import java.util.HashMap;
import java.util.Map;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

import com.action.base.BaseAction;
import com.opensymphony.xwork2.ModelDriven;
import com.pageModel.Json;
import com.pageModel.Union;
import com.service.school.UnionServiceI;

/**
 * 校友会Action
 * 
 * @author chenq
 * 
 */

@Namespace("/school")
@Action(value = "unionAction")
public class UnionAction extends BaseAction implements ModelDriven<Union>{

	Union union=new Union();
	
	@Override
	public Union getModel() {
		return union;
	}
	
	private UnionServiceI unionService;

	public UnionServiceI getUnionService() {
		return unionService;
	}
	@Autowired
	public void setUnionService(UnionServiceI unionService) {
		this.unionService = unionService;
	}
	
	public void add(){
		String json = null;
		Map<String, Object> m = new HashMap<String, Object>();
		try {
			unionService.add(union);
			m.put("success", true);
			m.put("msg", "添加成功!");
		} catch (Exception e) {
			e.printStackTrace();
			m.put("success", false);
			m.put("msg", "添加失败！");
			System.out.print(e.getMessage());
		}
		super.writeJson(m);
	}
	
	public void datagrid_SH(){
		super.writeJson(unionService.datagrid_SH(union));
	}
	
	public void datagrid_TG(){
		super.writeJson(unionService.datagrid_TG(union));
	}
	
	public void datagrid_BTG(){
		super.writeJson(unionService.datagrid_BTG(union));
	}
	
	public void datagrid(){
		super.writeJson(unionService.datagrid(union));
	}
	
	public void edit_TG(){
		unionService.edit_TG(union);
		Json j=new Json();
		j.setSuccess(true);
		j.setMsg("修改成功！");
		super.writeJson(j);
	}
	
	public void edit_TY(){
		unionService.edit_TY(union);
		Json j=new Json();
		j.setSuccess(true);
		j.setMsg("修改成功！");
		super.writeJson(j);
	}
	
	public void edit_BTG(){
		unionService.edit_BTG(union);
		Json j=new Json();
		j.setSuccess(true);
		j.setMsg("修改成功！");
		super.writeJson(j);
	}
	
	public void getUnionCmb(){
		super.writeJson(unionService.getUnionCmb(union));
	}

}
